package com.st.app.house.service;

import com.st.app.house.entities.HouseEntity;
import com.st.app.house.repositoty.HouseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author future
 * @Desc 房屋服务化:
 * *
 * @date 11/25/24
 */
@Service
public class HouseService {
    @Autowired
    private HouseRepository houseRepository;

    public List<HouseEntity> getAllHouseEntities() {
        return houseRepository.findAll();
    }

    public Optional<HouseEntity> getHouseEntityById(Long id) {
        return houseRepository.findById(id);
    }

    public HouseEntity createHouseEntity(HouseEntity HouseEntity) {
        return houseRepository.save(HouseEntity);
    }

    public HouseEntity updateHouseEntity(Long id, HouseEntity HouseEntity) {
        if (houseRepository.existsById(id)) {
            HouseEntity.setId(id);
            return houseRepository.save(HouseEntity);
        }
        return null;
    }

    public void deleteHouseEntity(Long id) {
        houseRepository.deleteById(id);
    }
    
}
